package com.zj.roseoj.judge.strategy;

import com.zj.roseoj.judge.strategy.impl.DefaultJudgeStrategy;
import com.zj.roseoj.judge.strategy.impl.JavaLanguageJudgeStrategy;
import com.zj.roseoj.model.dto.questionsumbit.JudgeInfo;
import com.zj.roseoj.model.entity.QuestionSubmit;
import org.springframework.stereotype.Service;

/**
 * 策略管理类（简化代码）
 */
@Service
public class JudgeManager {

    /**
     * 通过语言选择策略执行判题
     * @param judgeContext
     * @return
     */
    public JudgeInfo doJudge(JudgeContext judgeContext) {
        QuestionSubmit questionSubmit = judgeContext.getQuestionSubmit();
        String language = questionSubmit.getLanguage();
        JudgeStrategy judgeStrategy = new DefaultJudgeStrategy();
        if ("java".equals(language)){
            judgeStrategy = new JavaLanguageJudgeStrategy();
        }
        return judgeStrategy.doJudge(judgeContext);
    }
}
